package com.ry.novel.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ry.novel.model.dto.BookCommentInfo;
import com.ry.novel.model.dto.condition.CommentQuery;
import com.ry.novel.model.resp.Result;
import com.ry.novel.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author ry
 * @since 2022-04-10 10:52
 **/
@RequestMapping("/comment")
@RestController
public class CommentController {
    @Autowired
    private CommentService commentService;

    @PostMapping("/queryComment")
    public Result<Page<BookCommentInfo>> queryComment(@RequestBody CommentQuery commentQuery){
        Page<BookCommentInfo> infoPage = commentService.queryComment(commentQuery);


        return Result.ok(infoPage);
    }

    @PostMapping("/addComment")
    public Result<Void> addComment(@RequestBody BookCommentInfo info){
        commentService.addComment(info);

        return Result.ok();
    }

    @PostMapping("/updateComment")
    public Result<Void> updateComment(@RequestBody BookCommentInfo info){
        commentService.updateComment(info);

        return Result.ok();
    }

    @PostMapping("/deleteComment")
    public Result<Void> deleteComment(@RequestParam("id")Long id){
        commentService.deleteComment(id);

        return Result.ok();
    }
}
